<?php

namespace app\admin\model;

use app\common\model\BaseModel;
use think\Model;

use function now_time;

/**
 * 分类
 */
class AdminMenu extends BaseModel
{
    protected $autoWriteTimestamp = false;
    protected $pk                 = 'menu_id';
    /**
     * 表名,
     */
    protected $table = 'admin_menu';

    public static function build()
    {
        return new self();
    }

    public function parentMenu()
    {
        return $this->hasOne(AdminMenu::class, 'menu_id', 'pid');
    }

    public static function getListByGroup($group_id)
    {
        //超级管理员
        if ($group_id == 1) {
            $list = AdminMenu::build()
                             ->whereIn('status', 1)
                             ->whereIn('type', [1, 2])
                             ->column('menu_id');
        } else {
            $authList = AdminAuthGroup::build()
                                      ->where('group_id', $group_id)
                                      ->find();
            $list = $authList->menu_rules;
        }
        return AdminMenu::build()
                        ->whereIn('status', 1)
                        ->whereIn('type', [1, 2])
                        ->whereIn('menu_id', $list)
                        ->column('menu_url');
    }


}